.TH "lxi_discover" "3" "@version_date@" "liblxi @version@" "C Library Functions"

.SH "NAME"
lxi_discover \- search for LXI devices on network

.SH "SYNOPSIS"
.PP
.B #include <lxi.h>

.B int lxi_discover(lxi_info_t *info, int timeout, lxi_discover_t type);

.SH "DESCRIPTION"
.PP
The
.BR lxi_discover()
function searches for LXI devices or services on the local network using VXI-11
or mDNS/DNS-SD respectively. Which discover
.I type
is used is defined as follows:

.sp
.nf
typedef enum
{
    DISCOVER_VXI11,
    DISCOVER_MDNS
} lxi_discover_t;
.fi

.PP
During the discover operation events and results are returned by callbacks
registered via the
.I info
structure, defined as follows:
.sp
.nf
typedef struct
{
    void (*broadcast)(char *address, char *interface);
    void (*device)(char *address, char *id);
    void (*service)(char *address, char *id, char *service, int port);
} lxi_info_t;
.fi

.PP
The
.I broadcast
callback is called whenever a new network interface is searched (DISCOVER_VXI11 only).

The
.I device
callback is called whenever a new LXI device is found (DISCOVER_VXI11 only).

The
.I service
callback is called whenever a new LXI service is found (DISCOVER_MDNS only).

.PP
The
.I timeout
is in milliseconds.

.SH "RETURN VALUE"

Upon successful completion
.BR lxi_discover()
returns
.BR LXI_OK
, or
.BR LXI_ERROR
if an error occurred.

.SH EXAMPLE
.PP
The following example searches for LXI devices using VXI-11 and prints the ID
and IP addresses of found devices:

.nf
#include <stdio.h>
#include <lxi.h>

void broadcast(char *address, char *interface)
{
    printf("Broadcasting on interface %s\\n", interface);
}

void device(char *address, char *id)
{
    printf(" Found %s on address %s\\n", id, address);
}

int main()
{
    lxi_info_t info;

    // Initialize LXI library
    lxi_init();

    // Set up search information callbacks
    info.broadcast = &broadcast;
    info.device = &device;

    printf("Searching for LXI devices - please wait...\\n");

    // Search for LXI devices, 1 second timeout
    lxi_discover(&info, 1000, DISCOVER_VXI11);

    return 0;
}
.fi

.SH "SEE ALSO"
.BR lxi_discover_if (3)
.BR lxi_init (3)
.BR lxi_open (3),
.BR lxi_close (3)
.BR lxi_receive (3),
.BR lxi_disconnect (3),
